﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IQToolkit;
using IQToolkit.Data.Mapping;
using IQToolkitContrib;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LinqToVfp.Northwind.Tests {
    [TestClass]
    public class InsertEmptyTests : TestBase {
        [TestMethod]
        public void InsertEmptyValuesTest() {
            var connectionString = "data source=" + TestContext.TestDeploymentDir + @"\AllTypes;null=false";

            var context = new AllTypesTableDataContext(connectionString);
            var entity = new AllTypesTable { BinaryMemo = "test" };

            context.AllTypes.Insert(entity);

            Assert.AreNotEqual(entity.Id, 0);
        }
    }

    public partial class AllTypesTableDataContext : DbEntityContextBase {
        public AllTypesTableDataContext(string connectionString)
            : base(VfpQueryProvider.Create(connectionString, typeof(AllTypesTableDataContextAttributes).FullName)) {
        }

        public virtual IEntityTable<AllTypesTable> AllTypes {
            get { return this.GetTable<AllTypesTable>(); }
        }
    }

    public partial class AllTypesTableDataContextAttributes : AllTypesTableDataContext {
        public AllTypesTableDataContextAttributes(string connectionString)
            : base(connectionString) {
        }

        [Table(Name = "AllTypesTables")]
        [Column(Member = "Id", IsPrimaryKey = true, IsGenerated = true)]
        [Column(Member = "Char")]
        [Column(Member = "BinaryChar")]
        [Column(Member = "VarChar")]
        [Column(Member = "BinaryVarChar")]
        [Column(Member = "Memo")]
        [Column(Member = "BinaryMemo")]
        [Column(Member = "Currency")]
        [Column(Member = "Decimal")]
        [Column(Member = "Integer")]
        [Column(Member = "Logical")]
        [Column(Member = "Long")]
        [Column(Member = "Float")]
        [Column(Member = "Double")]
        [Column(Member = "Date")]
        [Column(Member = "DateTime")]
        [Column(Member = "Guid")]
        public override IEntityTable<AllTypesTable> AllTypes {
            get { return base.AllTypes; }
        }
    }

    public class AllTypesTable {
        public int Id { get; set; }
        public string Char { get; set; }
        public string BinaryChar { get; set; }
        public string VarChar { get; set; }
        public string BinaryVarChar { get; set; }
        public string Memo { get; set; }
        public string BinaryMemo { get; set; }
        public decimal? Currency { get; set; }
        public decimal? Decimal { get; set; }
        public int? Integer { get; set; }
        public bool? Logical { get; set; }
        public long? Long { get; set; }
        public float? Float { get; set; }
        public double? Double { get; set; }
        public DateTime? Date { get; set; }
        public DateTime? DateTime { get; set; }
        public Guid? Guid { get; set; }
    }
}